package com.jiacloud.web.controller;

import com.jiacloud.web.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UserInfoService userInfoService;

    @GetMapping(value = "/port")
    public String getPort(){
        //使用ribbon方式远程调用
        String port = restTemplate.getForEntity("http://EUREKA-CLIENT/test",String.class).getBody();
        return port;
    }

    @GetMapping(value = "/baidu")
    public String baidu(){
        String port = restTemplate.getForEntity("http://www.baidu.com",String.class).getBody();
        return port;
    }

    @GetMapping("/user")
    public String getUser(){
        //使用feign方式调用--此类又进行了一次封装，更像注解式开发（推荐）
        return this.userInfoService.getUser();
    }
}
